﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.enprise
{
    public partial class ListInterview : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心—简历管理：您邀请面试的简历  {0}", Application["webname"].ToString());
                }
                int enterprise_bid = -1;

                if (Session["enterprise_bid"] != null)
                {
                    enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                    Bind(enterprise_bid);

                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }

            }

            //form1.Target = "_blank";
        }

        private void Bind(int enterprise_bid)
        {
            int count = 0;

            DataSet ds = new lcmyjobs.BLL.enterprise_interview().GetInterview(enterprise_bid, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out count);

            if (ds.Tables[1].Rows.Count > 0)
            {
                this.lbl_title.Text = " " + ds.Tables[1].Rows[0]["name"].ToString();
                this.lbl_count.Text = count.ToString();
            }

            this.AspNetPager1.RecordCount = count;

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            int enterprise_bid = -1;
            if (Session["enterprise_bid"] != null)
            {
                enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                Bind(enterprise_bid);

            }
        }
        //参加面试
        protected void lbn_join_Click(object sender, EventArgs e)
        {

            string idlist = GetSelIDlist();
            if (!string.IsNullOrEmpty(idlist))
            {
                lcmyjobs.BLL.enterprise_interview er = new BLL.enterprise_interview();

                if (er.UpdateWhere("iscome", "1", idlist))
                {
                    Maticsoft.Common.MessageBox.Show(this, "已参加面试！");
                    int enterprise_bid = -1;
                    if (Session["enterprise_bid"] != null)
                    {
                        enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                        Bind(enterprise_bid);

                    }
                }
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请选择所要参加面试的简历！", "ListInterview.html");
            }
        }
        //面试成功
        protected void lbn_success_Click(object sender, EventArgs e)
        {
            string idlist = GetSelIDlist();
            if (!string.IsNullOrEmpty(idlist))
            {
                lcmyjobs.BLL.enterprise_interview er = new BLL.enterprise_interview();

                if (er.UpdateWhere("issuccess", "1", idlist))
                {
                    Maticsoft.Common.MessageBox.Show(this, "面试成功！");
                    int enterprise_bid = -1;
                    if (Session["enterprise_bid"] != null)
                    {
                        enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                        Bind(enterprise_bid);

                    }
                }
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请选择面试成功的简历！", "ListInterview.html");
            }
        }
        //批量删除
        protected void lbn_dels_Click(object sender, EventArgs e)
        {
            lcmyjobs.BLL.enterprise_interview bll = new BLL.enterprise_interview();
            string idlist = GetSelIDlist();
            if (idlist.Trim().Length != 0)
            {
                if (bll.DeleteList(idlist))
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "删除成功！", "ListInterview.html");
                }
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请选择所要删除的简历！", "ListInterview.html");
            }

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                if (e.CommandArgument != null)
                {
                    int enterprise_iid = Convert.ToInt32(e.CommandArgument);

                    lcmyjobs.BLL.enterprise_interview er = new BLL.enterprise_interview();

                    if (er.Delete(enterprise_iid))
                    {
                        int enterprise_bid = -1;

                        if (Session["enterprise_bid"] != null)
                        {
                            enterprise_bid = Convert.ToInt32(Session["enterprise_bid"]);

                            Bind(enterprise_bid);

                        }
                    }

                }

            }

            else if (e.CommandName == "look")
            {
                // add by liuhui 20131109 
                // 查看面试说明

                if (e.CommandArgument != null)
                {
                    Session["enterprise_iid"] = e.CommandArgument.ToString();
                    //string showOpen = "<script language='javascript'>window.open('InterviewDetail.aspx')</script>";   
                    string showOpen = "<script language='javascript'>window.open('SetTop.aspx')</script>";

                    ClientScriptManager CSM = Page.ClientScript;
                    string ScriptName = "clientScript";
                    if (!CSM.IsClientScriptBlockRegistered(ScriptName))
                    {
                        string strScript = "<script>";
                        strScript += "function OpenWin(){";
                        strScript += "showModalDialog('SetTop.aspx','');";
                        strScript += "return false;";
                        strScript += "}";
                        strScript += "</script>";
                        //CSM.RegisterStartupScript(this.GetType(), ScriptName, strScript);
                        CSM.RegisterClientScriptBlock(this.GetType(), ScriptName, strScript);
                        Response.Write(strScript);
                    }
                    
                    /*
                    if (!IsClientScriptBlockRegistered("clientScript"))
                    {
                        RegisterClientScriptBlock("clientScript", showOpen);
                    }
                    else
                    {
                        Response.Write(showOpen);
                    }
                     * */
                    /*
                    string enterprise_iid = e.CommandArgument.ToString();

                    lcmyjobs.BLL.enterprise_interview er = new BLL.enterprise_interview();

                    DataSet ds = er.GetInterviewbyiid(enterprise_iid);
                    
                    if (ds.Tables[0].Rows.Count>0)
                    {
                       
                        
                    }
                     * */

                } // end of e.CommandArgument
            }
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)this.GridView1.Rows[i].FindControl("cbo_rid");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (GridView1.DataKeys[i].Value != null)
                    {
                        idlist += GridView1.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }

    }
}